package com.bringway.p2p.controller;

import java.io.OutputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bringway.framework.controller.JsonController;
import com.bringway.framework.excel.ExcelOperUtil;
import com.bringway.framework.excel.ExcelSheet;
import com.bringway.framework.util.DateUtils;
import com.bringway.framework.util.RequestUtils;
import com.bringway.global.domain.SysUserDetails;
import com.bringway.global.util.StringUtils;
import com.bringway.p2p.service.P2pHplanService;

import net.sf.json.JSONObject;

/**  
 * @类名 p2pHplanController  
 * @功能 TODO  H计划Controller层
 * @作者 js 
 * @日期 2017年4月18日 上午10:53:42  
 *    
 */
@Controller
@RequestMapping("/hPlan")
public class P2pHplanController extends JsonController{
	@Autowired
	private P2pHplanService p2pHplanService;
	
	private Logger logger=Logger.getLogger(P2pHplanController.class);
	
	/**
	 * @作者 js  
	 * @方法名 listXmSq  
	 * @功能 TODO 获取H计划发标申请列表
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/listXmSq")
	public ModelAndView listXmSq(HttpServletRequest request,HttpServletResponse response)throws Exception {
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String xmmc = RequestUtils.getStringParameter(request, "xmmc");
		String zt = RequestUtils.getStringParameter(request, "zt");
		String sqr = RequestUtils.getStringParameter(request, "sqr");
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("xmmc", xmmc);
		params.put("zt", zt);
		params.put("sqr", sqr);
		List<Map<String, Object>> list=p2pHplanService.listXmSq(params);
		int count=p2pHplanService.getXmSqCount(params);
		result.put("data", list);
		result.put("total", count);
		serialize(request, response, result);
		return null;
	}
	/**
	 * @作者 js  
	 * @方法名 listXmKu  
	 * @功能 TODO 获取项目库信审通过的待组合项目列表
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/listXmKu")
	public ModelAndView listXmKu(HttpServletRequest request,HttpServletResponse response)throws Exception {
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String xmmc = RequestUtils.getStringParameter(request, "xmmc");
		String zt = RequestUtils.getStringParameter(request, "zt");
		String qxMonth = RequestUtils.getStringParameter(request, "qxMonth");
		params.put("start", start);
		params.put("limit", 0);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("xmmc", xmmc);
		params.put("zt", zt);
		params.put("qxMonth", qxMonth);
		params.put("isUsed", "00");
		List<Map<String, Object>> list=p2pHplanService.listXmKu(params);
		int count=p2pHplanService.getXmKuCount(params);
		result.put("data", list);
		result.put("total", count);
		serialize(request, response, result);
		return null;
	}
	/**
	 * @作者 js  
	 * @方法名 listKuByXmId  
	 * @功能 TODO 获取申请标的选择的项目列表
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/listKuByXmId")
	public ModelAndView listKuByXmId(HttpServletRequest request,HttpServletResponse response)throws Exception {
		JSONObject result = new JSONObject();
		String xmId = RequestUtils.getStringParameter(request, "xmId");
		List<Map<String, Object>> list=p2pHplanService.listKuByXmId(xmId);
		int count=p2pHplanService.getKuByXmIdCount(xmId);
		result.put("data", list);
		result.put("total", count);
		serialize(request, response, result);
		return null;
	}
	/**
	 * @作者 js  
	 * @方法名 saveXmSq  
	 * @功能 TODO 保存H计划组合项目发标申请
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/saveXmSq")
	public ModelAndView saveXmSq(HttpServletRequest request,HttpServletResponse response) throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		String gyh = sysUserDetails.getGyh();
		String xmmc = RequestUtils.getStringParameter(request, "xmmc");
		String nhsyl = RequestUtils.getStringParameter(request, "nhsyl");
		String qx_month = RequestUtils.getStringParameter(request, "qx_month");
		String mjq = RequestUtils.getStringParameter(request, "mjq");
		String xmje = RequestUtils.getStringParameter(request, "xmje");
		String gridId = RequestUtils.getStringParameter(request, "gridId");
		String tbfw = RequestUtils.getStringParameter(request, "tbfw");
		String jhjs = RequestUtils.getStringParameter(request, "jhjs");
		String hklx = RequestUtils.getStringParameter(request, "hklx");
		
		params.put("xmmc", xmmc);
		params.put("tbfw", tbfw);
		params.put("jhjs", jhjs);
		params.put("nhsyl", nhsyl);
		params.put("qx_month", qx_month);
		params.put("mjq", mjq);
		params.put("xmje", xmje);
		params.put("sqr", gyh);
		params.put("fbsj", DateUtils.getCurrentDataStr()+" 17:00:00");
		params.put("gridId", gridId);
		params.put("hklx", hklx);
		try {
			result=p2pHplanService.saveXmSq(params);
		} catch (Exception e) {
			logger.error(e);
			result.put("success", true);
			result.put("isSuc", false);
			result.put("msg", "保存申请失败");
			serialize(request, response, result);
			return null;
		}
		serialize(request, response, result);
		return null;
	}
	/**
	 * @作者 js  
	 * @方法名 saveXmSh  
	 * @功能 TODO 保存H计划组合项目发标审核
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/saveXmSh")
	public ModelAndView saveXmSh(HttpServletRequest request,HttpServletResponse response) throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		String gyh = sysUserDetails.getGyh();
		String xmSqId = RequestUtils.getStringParameter(request, "xmId");
		String shr = RequestUtils.getStringParameter(request, "shr");
		String shzt = RequestUtils.getStringParameter(request, "shzt");
		String shbz = RequestUtils.getStringParameter(request, "shbz");
		if (!StringUtils.equals(shr, gyh)) {
			logger.error("审核人与登陆人不一致");
			result.put("isSuc", false);
			result.put("msg", "登陆信息不一致,请重新登陆");
			serialize(request, response, result);
			return null;
		}
		params.put("xmSqId", xmSqId);
		params.put("shr", gyh);
		params.put("shzt", shzt);
		params.put("shbz", shbz);
		try {
			result=p2pHplanService.saveXmSh(params);
		} catch (Exception e) {
			logger.error(e);
			result.put("success", true);
			result.put("isSuc", false);
			result.put("msg", "保存审核失败");
			serialize(request, response, result);
			return null;
		}
		result.put("success", true);
		serialize(request, response, result);
		return null;
	}
	/**
	 * 
	 * @param request H计划项目查询
	 * @param response 查询功能
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryHplanList")
	public ModelAndView queryZqshcgList(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String xmname = RequestUtils.getStringParameter(request, "xmname");
		String jkzh = RequestUtils.getStringParameter(request, "jkzh");
		String shrid = RequestUtils.getStringParameter(request, "shrid");
		String xmType = RequestUtils.getStringParameter(request, "xmType");
		String state = RequestUtils.getStringParameter(request, "state");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("xmname", xmname);
		params.put("jkzh", jkzh);
		params.put("shrid", shrid);
		params.put("xmType", xmType);
		params.put("state", state);
		List list = p2pHplanService.queryHplanList(params);
		int count = p2pHplanService.getHplanCount(params);
		result.put("data", list);	
		result.put("total", count);
		if (null!=page) {//新版本,传参
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
		}
		serialize(request,response,result);
		return null;
	}
	/**
	 * 申请月，根据期限(月)，获得实际天数
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getQxDayByQxMonth")
	public ModelAndView getQxDayByQxMonth(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		String qxMonth = RequestUtils.getStringParameter(request, "qxMonth");
		int qxDay = this.p2pHplanService.getQxDayByQxMonth(qxMonth);
		if(qxDay > 0){
			result.put("success", true);
			result.put("msg", "获取实际期限(天)成功！");
			result.put("qxDay", qxDay);
		}else{
			result.put("success", false);
			result.put("msg", "获取实际期限(天)失败！");
			result.put("qxDay", qxDay);
		}
		serialize(request,response,result);
		return null;
	}
	/**
	 * 
	 * @param request 申请的草稿标
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/saveHplanList")
	public ModelAndView saveHplanList(HttpServletRequest request,HttpServletResponse response) throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		String xmmc = RequestUtils.getStringParameter(request, "xmmc");
		String nhsyl = RequestUtils.getStringParameter(request, "nhsyl");
		String xmje = RequestUtils.getStringParameter(request, "xmje");
		String day = RequestUtils.getStringParameter(request, "day");
		String ssgyh = RequestUtils.getStringParameter(request, "ssgyh");
		String nouth = RequestUtils.getStringParameter(request, "nouth");
		String xmsqr = RequestUtils.getStringParameter(request, "xmsqr");
		String sqr = null!=sysUserDetails?sysUserDetails.getGyh():"";//默认发标人
		String state = RequestUtils.getStringParameter(request, "state");
		String xmjs = RequestUtils.getStringParameter(request, "xmjs");
		String xmfw = RequestUtils.getStringParameter(request, "xmfw");
		String atts = RequestUtils.getStringParameter(request, "atts");
		params.put("xmmc", xmmc);
		params.put("nhsyl", nhsyl);
		params.put("xmje", xmje);
		params.put("day", day);
		params.put("ssgyh", ssgyh);
		params.put("nouth", nouth);
		params.put("sqr", sqr);
		params.put("state", state);
		params.put("xmjs", xmjs);
		params.put("xmfw", xmfw);
		params.put("atts", atts);
		
		try{
			if (xmsqr.equals(sqr)) {
				p2pHplanService.saveHplan(params);
				result.put("success", true);
				result.put("isAddSuc", true);
			}else{
				logger.info("申请人与登录人不一致,请重新登陆");
				result.put("success", true);
				result.put("isAddSuc", false);
			}
				
		}catch(Exception e){
			e.printStackTrace();
			logger.info("saveHplanList 申请保存失败! " + e.getMessage());
			result.put("success", true);
			result.put("isAddSuc", false);
		}
		serialize(request,response,result);
		return null;
	}
	/**
	 * @作者 qjy  
	 * @方法名 saveSHPlan  
	 * @功能 TODO 保存H计划基本审核
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/saveSHPlan")
	public ModelAndView saveSHPlan(HttpServletRequest request,HttpServletResponse response) throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		String gyh = sysUserDetails.getGyh();
		String hid = RequestUtils.getStringParameter(request, "hid");
		String hshr = RequestUtils.getStringParameter(request, "hshr");
		String hstate = RequestUtils.getStringParameter(request, "hstate");
		String hxyjb = RequestUtils.getStringParameter(request, "hxyjb");
		String hshbz = RequestUtils.getStringParameter(request, "hshbz");
		String atts = RequestUtils.getStringParameter(request, "atts");
		if (!StringUtils.equals(hshr, gyh)) {
			logger.error("审核人与登陆人不一致");
			result.put("isSuc", false);
			result.put("msg", "登陆信息不一致,请重新登陆");
			serialize(request, response, result);
			return null;
		}
		params.put("hid", hid);
		params.put("hshr", gyh);
		params.put("hstate", hstate);
		params.put("hshbz", hshbz);
		params.put("hxyjb", hxyjb);
		params.put("atts", atts);
		try {
			result=p2pHplanService.saveShplan(params);
		} catch (Exception e) {
			logger.error(e);
			result.put("success", true);
			result.put("isSuc", false);
			result.put("msg", "保存审核失败");
			serialize(request, response, result);
			return null;
		}
		result.put("success", true);
		serialize(request, response, result);
		return null;
	}
	/**
	 * 
	 * @param request H组合计划项目查询
	 * @param response 查询功能
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryHzhjh")
	public ModelAndView queryHzhjh(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String xmname = RequestUtils.getStringParameter(request, "xmname");
		String xmtype = RequestUtils.getStringParameter(request, "xmtype");
		String hktype = RequestUtils.getStringParameter(request, "hktype");
		String hkstate = RequestUtils.getStringParameter(request, "hkstate");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("xmname", xmname);
		params.put("xmtype", xmtype);
		params.put("hktype", hktype);
		params.put("hkstate", hkstate);
		List<Map<String, Object>> list = p2pHplanService.queryHzhjh(params);
		int count = p2pHplanService.getHzhjhCount(params);
		String sumJe=p2pHplanService.geHzhjhSum(params);
		DecimalFormat df = new DecimalFormat("#,###");
		result.put("data", list);	
		result.put("total", count);
		result.put("sumJe", null==sumJe?"":df.format(new Double(sumJe)));
		if (null!=page) {
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
			//合计行 数据 开始
			Map<String, Object> map=new HashMap<>();
			map.put("H_PLAN_XM_NAME", "合计:");//key是字段名
			map.put("H_PLAN_XM_JE", null==sumJe?"":df.format(new Double(sumJe)));//key是字段名
			result.put("userdata", map);
			//合计行 数据 结束
	}
		serialize(request,response,result);
		return null;
	}
	/**
	 * 
	 * @param request H组合计划项目投资记录查询
	 * @param response 查询功能
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryHtzjl")
	public ModelAndView queryHtzjl(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String userid = RequestUtils.getStringParameter(request, "userid");
		String htbh = RequestUtils.getStringParameter(request, "htbh");
		String hkzt = RequestUtils.getStringParameter(request, "hkzt");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("userid", userid);
		params.put("htbh", htbh);
		params.put("hkzt", hkzt);
		List<Map<String, Object>> list = p2pHplanService.queryHtzjl(params);
		int count = p2pHplanService.getHtzjlCount(params);
		String sumJe=p2pHplanService.geHtzjlSum(params);
		DecimalFormat df = new DecimalFormat("#,###");
		result.put("data", list);	
		result.put("total", count);
		result.put("sumJe", null==sumJe?"":df.format(new Double(sumJe)));
		if (null!=page) {
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
			//合计行 数据 开始
			Map<String, Object> map=new HashMap<>();
			map.put("H_PLAN_XM_NAME", "合计:");//key是字段名
			map.put("H_PLAN_XM_JE", null==sumJe?"":df.format(new Double(sumJe)));//key是字段名
			result.put("userdata", map);
			//合计行 数据 结束
	}
		serialize(request,response,result);
		return null;
	}
	
	
	/**
	 * 
	 * @param request H组合计划项目流标投资记录备份
	 * @param response 查询功能
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryHlbtzjl")
	public ModelAndView queryHlbtzjl(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String userid = RequestUtils.getStringParameter(request, "userid");
		String htbh = RequestUtils.getStringParameter(request, "htbh");
		String tzzt = RequestUtils.getStringParameter(request, "tzzt");
		String hkzt = RequestUtils.getStringParameter(request, "hkzt");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("userid", userid);
		params.put("htbh", htbh);
		params.put("tzzt", tzzt);
		params.put("hkzt", hkzt);
		List<Map<String, Object>> list = p2pHplanService.queryHlbtzjl(params);
		int count = p2pHplanService.getHlbtzjlCount(params);
		String sumJe=p2pHplanService.geHlbtzjlSum(params);
		DecimalFormat df = new DecimalFormat("#,###");
		result.put("data", list);	
		result.put("total", count);
		result.put("sumJe", null==sumJe?"":df.format(new Double(sumJe)));
		if (null!=page) {
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
			//合计行 数据 开始
			Map<String, Object> map=new HashMap<>();
			map.put("H_PLAN_XM_NAME", "合计:");//key是字段名
			map.put("H_PLAN_XM_JE", null==sumJe?"":df.format(new Double(sumJe)));//key是字段名
			result.put("userdata", map);
			//合计行 数据 结束
	}
		serialize(request,response,result);
		return null;
	}
	/**
	 * 
	 * @param request H组合计划项目收益发放明细
	 * @param response 查询功能
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryHsyffmx")
	public ModelAndView queryHsyffmx(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String username = RequestUtils.getStringParameter(request, "username");
		String xmid = RequestUtils.getStringParameter(request, "xmid");
		String hkzt = RequestUtils.getStringParameter(request, "hkzt");
		String hklx = RequestUtils.getStringParameter(request, "hklx");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("username", username);
		params.put("xmid", xmid);
		params.put("hkzt", hkzt);
		params.put("hklx", hklx);
		List<Map<String, Object>> list = p2pHplanService.queryHsyffmx(params);
		int count = p2pHplanService.getHsyffmxCount(params);
		result.put("data", list);	
		result.put("total", count);
		if (null!=page) {//新版本,传参
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
		}
		serialize(request,response,result);
		return null;
	}
	/**
	 * 
	 * @param request H组合计划项目还款明细
	 * @param response 查询功能
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryHhk")
	public ModelAndView queryHhk(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String xmid = RequestUtils.getStringParameter(request, "xmid");
		String xmmc = RequestUtils.getStringParameter(request, "xmmc");
		String jkrname = RequestUtils.getStringParameter(request, "jkrname");
		String hkqszt = RequestUtils.getStringParameter(request, "hkqszt");
		String xmlx = RequestUtils.getStringParameter(request, "xmlx");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("xmid", xmid);
		params.put("xmmc", xmmc);
		params.put("jkrname", jkrname);
		params.put("hkqszt", hkqszt);
		params.put("xmlx", xmlx);
		List<Map<String, Object>> list = p2pHplanService.queryHhk(params);
		int count = p2pHplanService.getHhkCount(params);
		result.put("data", list);	
		result.put("total", count);
		if (null!=page) {//新版本,传参
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
		}
		serialize(request,response,result);
		return null;
	}
	/**
	 * 
	 * @param request
	 * @param response
	 * @return  导出excel表格
	 * @throws Exception
	 */
	@RequestMapping("exportHhkExcelMethod")
	public ModelAndView exportHhkExcelMethod(HttpServletRequest request, HttpServletResponse response) throws Exception{
		JSONObject params = new JSONObject();
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String xmid = RequestUtils.getStringParameter(request, "xmid");
		String xmmc = RequestUtils.getStringParameter(request, "xmmc");
		String jkrname = RequestUtils.getStringParameter(request, "jkrname");
		String hkqszt = RequestUtils.getStringParameter(request, "hkqszt");
		String xmlx = RequestUtils.getStringParameter(request, "xmlx");
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("xmid", xmid);
		params.put("xmmc", xmmc);
		params.put("jkrname", jkrname);
		params.put("hkqszt", hkqszt);
		params.put("xmlx", xmlx);
		// 查询数据
		List<Map<String, Object>> list = p2pHplanService.queryHhk(params);
		List<String[]> dataList = com.bringway.p2p.constant.ExcelHeadConstant.exportHhkExcelMethod(list);
		// 导出数据到Excel文件
		List<ExcelSheet> sheetList = new ArrayList<ExcelSheet>();
		ExcelSheet sheet = new ExcelSheet();
		sheet.setBodyList(dataList);
		sheet.setSheetName(DateUtils.getCurrentDataStr()+"H计划还款信息");
		sheetList.add(sheet);
		OutputStream os = response.getOutputStream();
		String fileName = DateUtils.getCurrentDataStr() + "H计划还款信息.xls";
		super.setDownLoadResponseHeader(request, response, fileName);
		response.setContentType("application/vnd.ms-excel");
		// 导出EXCEL
		ExcelOperUtil.writeExcel(sheetList, os);
		return null;
	}
	/**
	 * 
	 * @param request
	 * @param response
	 * @return  导出excel表格
	 * @throws Exception
	 */
	@RequestMapping("exportsyffmxExcelMethod")
	public ModelAndView exportsyffmxExcelMethod(HttpServletRequest request, HttpServletResponse response) throws Exception{
		JSONObject params = new JSONObject();
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String username = RequestUtils.getStringParameter(request, "username");
		String xmid = RequestUtils.getStringParameter(request, "xmid");
		String hkzt = RequestUtils.getStringParameter(request, "hkzt");
		String hklx = RequestUtils.getStringParameter(request, "hklx");
		
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("username", username);
		params.put("xmid", xmid);
		params.put("hkzt", hkzt);
		params.put("hklx", hklx);
		// 查询数据
		List<Map<String, Object>> list =p2pHplanService.queryHsyffmx(params);
		List<String[]> dataList = com.bringway.p2p.constant.ExcelHeadConstant.exportsyffmxExcelMethod(list);
		// 导出数据到Excel文件
		List<ExcelSheet> sheetList = new ArrayList<ExcelSheet>();
		ExcelSheet sheet = new ExcelSheet();
		sheet.setBodyList(dataList);
		sheet.setSheetName(DateUtils.getCurrentDataStr()+"H计划收益发放明细");
		sheetList.add(sheet);
		OutputStream os = response.getOutputStream();
		String fileName = DateUtils.getCurrentDataStr() + "H计划收益发放明细.xls";
		super.setDownLoadResponseHeader(request, response, fileName);
		response.setContentType("application/vnd.ms-excel");
		// 导出EXCEL
		ExcelOperUtil.writeExcel(sheetList, os);
		return null;
	}
	@RequestMapping("exportHtzjlExcelMethod")
	public ModelAndView exportHtzjlExcelMethod(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		JSONObject params = new JSONObject();
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String yhm= RequestUtils.getStringParameter(request, "yhm");
		String sjhm= RequestUtils.getStringParameter(request, "sjhm");
		String ltype= RequestUtils.getStringParameter(request, "ltype");
		String lyb= RequestUtils.getStringParameter(request, "lyb");
		params.put("lyb", lyb);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("yhm", yhm);
		params.put("sjhm", sjhm);
		params.put("ltype", ltype);
		List<Map<String, Object>> list= p2pHplanService.queryHtzjl(params);
		List<String[]> dataList = com.bringway.p2p.constant.ExcelHeadConstant.exportHtzjlExcelMethod(list);
		// 导出数据到Excel文件
		List<ExcelSheet> sheetList = new ArrayList<ExcelSheet>();
		ExcelSheet sheet = new ExcelSheet();
		sheet.setBodyList(dataList);
		sheet.setSheetName(DateUtils.getCurrentDataStr() + "H计划投资记录");
		sheetList.add(sheet);
		OutputStream os = response.getOutputStream();
		String fileName = DateUtils.getCurrentDataStr() + "H计划投资记录.xls";
		super.setDownLoadResponseHeader(request, response, fileName);
		response.setContentType("application/vnd.ms-excel");

		// 导出EXCEL
		ExcelOperUtil.writeExcel(sheetList, os);
		return null;
	}
	@RequestMapping("exportHlbtzjlExcelMethod")
	public ModelAndView exportHlbtzjlExcelMethod(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		JSONObject params = new JSONObject();
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		String userid = RequestUtils.getStringParameter(request, "userid");
		String htbh = RequestUtils.getStringParameter(request, "htbh");
		String tzzt = RequestUtils.getStringParameter(request, "tzzt");
		String hkzt = RequestUtils.getStringParameter(request, "hkzt");
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		params.put("userid", userid);
		params.put("htbh", htbh);
		params.put("tzzt", tzzt);
		params.put("hkzt", hkzt);
		List<Map<String, Object>> list = p2pHplanService.queryHlbtzjl(params);
		List<String[]> dataList = com.bringway.p2p.constant.ExcelHeadConstant.exportHlbtzjlExcelMethod(list);
		// 导出数据到Excel文件
		List<ExcelSheet> sheetList = new ArrayList<ExcelSheet>();
		ExcelSheet sheet = new ExcelSheet();
		sheet.setBodyList(dataList);
		sheet.setSheetName(DateUtils.getCurrentDataStr() + "H计划流标投资记录");
		sheetList.add(sheet);
		OutputStream os = response.getOutputStream();
		String fileName = DateUtils.getCurrentDataStr() + "H计划流标投资记录.xls";
		super.setDownLoadResponseHeader(request, response, fileName);
		response.setContentType("application/vnd.ms-excel");

		// 导出EXCEL
		ExcelOperUtil.writeExcel(sheetList, os);
		return null;
	}
	
}
